import React, { PureComponent } from "react"
import {Route, Redirect} from "react-router-dom"
import {connect} from "react-redux"
import {bindActionCreators} from "redux"

@connect(
    ({user: {userInfo}}) => ({userInfo}),
    (dispatch) => (
        bindActionCreators({
        }, dispatch)
    )
)
export default class Index extends PureComponent {
  render() {
    let {userInfo, component: Component} = this.props
    return (
      <Route
        render={props => (
                userInfo ? (
                  <Component
                    {...props}/>
                ):(
                  <Redirect
                    to={{
                      pathname: "login",
                      state: {
                        from: props.location
                      }
                    }}
                  />
                )
            )}
      />
    )
  }
}